#!/usr/bin/python
# -*- coding: utf-8 -*-

import socket
import urllib
import hashlib

socket.setdefaulttimeout(10)

input = open('thumbnail_urls', 'r')
cnt = -1
for url in input.readlines():
    cnt = cnt + 1
    try:
        output = open('thumbnails/' + str(cnt) + '.jpg', 'w')
        data = urllib.urlopen(url).read()
        output.write(data)
        output.close()
        #print hashlib.md5(data).hexdigest()
    except Exception, data:
        print Exception, ': ', data

input.close()
